import pickle
import json
import os
'''
list = [1,2,4,5]
print(json.dumps(list),type(json.dumps(list)))
list = (1,2,4,5)
print(json.dumps(list),type(json.dumps(list)))
list = {1,2,3,4,5}
#Object of type set is not JSON serializable
#print(json.dumps(list),type(json.dumps(list)))
list = {'name':'zhangsan','age':23,'gender':'woman'}
print(json.dumps(list),type(json.dumps(list)))



list = '{"name":"zhangsan","age":23,"gender":"woman"}'
print(list,type(list))
print(json.loads(list),type(json.loads(list)))
'''

#json.dumps
def read() :
    with open('./example.cvs' ,'r+') as file :
        list = []
        for line in file.readlines() :
            print(line)
            line =json.loads(line)

            if line.get('name') == 'zhangsan' :
                line.setdefault('english',80)
            list.append(line)

        write(list)




#json.loads
def write(list,type='w'):
    if not os.path.exists('./example.cvs') :
        type = 'a+'
    with open('./example.cvs' ,type) as file :
        if isinstance(list,dict) :
            list = json.dumps(list)
            file.write(list)
        else:
            print('type不正确')

#json.dump

def json_write(list):
    with open('text.json','w') as f :
        json.dump(list,f)

#json.load
def json_read() :
    with open('text.json','r') as f :
        list = json.load(f)
        return list


if  __name__ =='__main__' :
    list = {'name':'zhangsan','age':23,'gender':'woman'}
    #write(list)
    #read()
    #json_write(list)
    print(type(json_read()))
